home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / program / rcs5ap1s.lzh / CO.C < prev    next >
C/C++ Source or Header  |  1991-01-30  |  23KB  |  785 lines

  1. /* Copyright (C) 1982, 1988, 1989 Walter Tichy
  2.    Copyright 1990 by Paul Eggert
  3.    Distributed under license by the Free Software Foundation, Inc.
  4.  
  5. This file is part of RCS.
  6.  
  7. RCS is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 1, or (at your option)
  10. any later version.
  11.  
  12. RCS is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with RCS; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21. Report problems and direct all questions to:
  22.  
  23.     rcs-bugs@cs.purdue.edu
  24.  
  25. */
  26.  
  27. /*
  28.  *                     RCS checkout operation
  29.  */
  30. /*****************************************************************************
  31.  *                       check out revisions from RCS files
  32.  *****************************************************************************
  33.  */
  34.  
  35.  
  36. /* $Log: co.c,v $
  37.  * Revision 5.10  1991/01/30  14:21:32  apratt
  38.  * CI with RCS version 5
  39.  *
  40.  * Revision 5.9  91/01/30  12:02:34  apratt
  41.  * Changed RCS5AKP1 to RCS5AP1
  42.  * 
  43.  * Revision 5.8  91/01/29  17:45:24  apratt
  44.  * Added RCS5AKP1 to usage message
  45.  * 
  46.  * Revision 5.7  91/01/11  12:45:34  apratt
  47.  * First version that compiles.
  48.  * 
  49.  * Revision 5.6  90/12/04  05:18:38  eggert
  50.  * checked in with -k by apratt at 91.01.10.13.14.50.
  51.  * 
  52.  * Revision 5.6  1990/12/04  05:18:38  eggert
  53.  * Don't checkaccesslist() unless necessary.
  54.  * Use -I for prompts and -q for diagnostics.
  55.  *
  56.  * Revision 5.5  1990/11/01  05:03:26  eggert
  57.  * Fix -j.  Add -I.
  58.  *
  59.  * Revision 5.4  1990/10/04  06:30:11  eggert
  60.  * Accumulate exit status across files.
  61.  *
  62.  * Revision 5.3  1990/09/11  02:41:09  eggert
  63.  * co -kv yields a readonly working file.
  64.  *
  65.  * Revision 5.2  1990/09/04  08:02:13  eggert
  66.  * Standardize yes-or-no procedure.
  67.  *
  68.  * Revision 5.0  1990/08/22  08:10:02  eggert
  69.  * Permit multiple locks by same user.  Add setuid support.
  70.  * Remove compile-time limits; use malloc instead.
  71.  * Permit dates past 1999/12/31.  Switch to GMT.
  72.  * Make lock and temp files faster and safer.
  73.  * Ansify and Posixate.  Add -k, -V.  Remove snooping.  Tune.
  74.  *
  75.  * Revision 4.7  89/05/01  15:11:41  narten
  76.  * changed copyright header to reflect current distribution rules
  77.  * 
  78.  * Revision 4.6  88/08/09  19:12:15  eggert
  79.  * Fix "co -d" core dump; rawdate wasn't always initialized.
  80.  * Use execv(), not system(); fix putchar('\0') and diagnose() botches; remove lint
  81.  * 
  82.  * Revision 4.5  87/12/18  11:35:40  narten
  83.  * lint cleanups (from Guy Harris)
  84.  * 
  85.  * Revision 4.4  87/10/18  10:20:53  narten
  86.  * Updating version numbers changes relative to 1.1, are actually
  87.  * relative to 4.2
  88.  * 
  89.  * Revision 1.3  87/09/24  13:58:30  narten
  90.  * Sources now pass through lint (if you ignore printf/sprintf/fprintf 
  91.  * warnings)
  92.  * 
  93.  * Revision 1.2  87/03/27  14:21:38  jenkins
  94.  * Port to suns
  95.  * 
  96.  * Revision 4.2  83/12/05  13:39:48  wft
  97.  * made rewriteflag external.
  98.  * 
  99.  * Revision 4.1  83/05/10  16:52:55  wft
  100.  * Added option -u and -f.
  101.  * Added handling of default branch.
  102.  * Replaced getpwuid() with getcaller().
  103.  * Removed calls to stat(); now done by pairfilenames().
  104.  * Changed and renamed rmoldfile() to rmworkfile().
  105.  * Replaced catchints() calls with restoreints(), unlink()--link() with rename();
  106.  * 
  107.  * Revision 3.7  83/02/15  15:27:07  wft
  108.  * Added call to fastcopy() to copy remainder of RCS file.
  109.  *
  110.  * Revision 3.6  83/01/15  14:37:50  wft
  111.  * Added ignoring of interrupts while RCS file is renamed; this avoids
  112.  * deletion of RCS files during the unlink/link window.
  113.  *
  114.  * Revision 3.5  82/12/08  21:40:11  wft
  115.  * changed processing of -d to use DATEFORM; removed actual from
  116.  * call to preparejoin; re-fixed printing of done at the end.
  117.  *
  118.  * Revision 3.4  82/12/04  18:40:00  wft
  119.  * Replaced getdelta() with gettree(), SNOOPDIR with SNOOPFILE.
  120.  * Fixed printing of "done".
  121.  *
  122.  * Revision 3.3  82/11/28  22:23:11  wft
  123.  * Replaced getlogin() with getpwuid(), flcose() with ffclose(),
  124.  * %02d with %.2d, mode generation for working file with WORKMODE.
  125.  * Fixed nil printing. Fixed -j combined with -l and -p, and exit
  126.  * for non-existing revisions in preparejoin().
  127.  *
  128.  * Revision 3.2  82/10/18  20:47:21  wft
  129.  * Mode of working file is now maintained even for co -l, but write permission
  130.  * is removed.
  131.  * The working file inherits its mode from the RCS file, plus write permission
  132.  * for the owner. The write permission is not given if locking is strict and
  133.  * co does not lock.
  134.  * An existing working file without write permission is deleted automatically.
  135.  * Otherwise, co asks (empty answer: abort co).
  136.  * Call to getfullRCSname() added, check for write error added, call
  137.  * for getlogin() fixed.
  138.  *
  139.  * Revision 3.1  82/10/13  16:01:30  wft
  140.  * fixed type of variables receiving from getc() (char -> int).
  141.  * removed unused variables.
  142.  */
  143.  
  144.  
  145.  
  146.  
  147. #include "rcsbase.h"
  148.  
  149. static const char *getancestor P((const char*,const char*));
  150. static int buildjoin P((const char*));
  151. static int creatempty P((void));
  152. static int fixworkmode P((const char*));
  153. static int preparejoin P((void));
  154. static int rmlock P((const struct hshentry*));
  155. static int rmworkfile P((void));
  156. static void cleanup P((void));
  157.  
  158. static const char quietarg[] = "-q";
  159.  
  160. static const char *join, *versionarg;
  161. static const char *joinlist[joinlength];/* revisions to be joined    */
  162. static int exitstatus;
  163. static int forceflag, tostdout;
  164. static int lastjoin;            /* index of last element in joinlist  */
  165. static int lockflag; /* -1 -> unlock, 0 -> do nothing, 1 -> lock */
  166. static struct hshentries *gendeltas;    /* deltas to be generated    */
  167. static struct hshentry *targetdelta;    /* final delta to be generated    */
  168.  
  169. mainProg(coId, "co", "$Id: co.c,v 5.10 1991/01/30 14:21:32 apratt Exp $")
  170. {
  171.     static const char cmdusage[] =
  172.         "\nRCS5AP1 as modified for TOS by Allan Pratt, atari!apratt\nco usage: co -{flpqru}[rev] -ddate -jjoinlist -sstate -w[login] -Vn file ...";
  173.  
  174.     const char *author, *date, *rev, *state;
  175.     const char *neworkfilename;
  176.     int changelock;  /* 1 if a lock has been changed, -1 if error */
  177.     int expmode, r;
  178.     struct buf numericrev;    /* expanded revision number    */
  179.     char finaldate[datesize];
  180.  
  181.     initid();
  182.     catchints();
  183.     author = date = rev = state = nil;
  184.     bufautobegin(&numericrev);
  185.     expmode = -1;
  186.     versionarg = nil;
  187.  
  188.         while (--argc,++argv, argc>=1 && ((*argv)[0] == '-')) {
  189.                 switch ((*argv)[1]) {
  190.  
  191.                 case 'r':
  192.                 revno:  if ((*argv)[2]!='\0') {
  193.                 if (rev) warn("redefinition of revision number");
  194.                                 rev = (*argv)+2;
  195.                         }
  196.                         break;
  197.  
  198.         case 'f':
  199.             forceflag=true;
  200.             goto revno;
  201.  
  202.                 case 'l':
  203.             if (lockflag < 0) {
  204.                                 warn("-l overrides -u.");
  205.                         }
  206.             lockflag = 1;
  207.                         goto revno;
  208.  
  209.                 case 'u':
  210.             if (0 < lockflag) {
  211.                                 warn("-l overrides -u.");
  212.                         }
  213.             lockflag = -1;
  214.                         goto revno;
  215.  
  216.                 case 'p':
  217.                         tostdout=true;
  218.                         goto revno;
  219.  
  220.         case 'I':
  221.             interactiveflag = true;
  222.             goto revno;
  223.  
  224.                 case 'q':
  225.                         quietflag=true;
  226.                         goto revno;
  227.  
  228.                 case 'd':
  229.             if (date)
  230.                 redefined('d');
  231.             str2date(*argv+2, finaldate);
  232.                         date=finaldate;
  233.                         break;
  234.  
  235.                 case 'j':
  236.                         if ((*argv)[2]!='\0'){
  237.                 if (join) redefined('j');
  238.                                 join = (*argv)+2;
  239.                         }
  240.                         break;
  241.  
  242.                 case 's':
  243.